package com.qf.cqut.Service.impl;

import com.qf.cqut.Service.UserService;
import com.qf.cqut.mapper.AUserMapper;
import com.qf.cqut.model.pojo.AUser;
import com.qf.cqut.util.MD5Util;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImp implements UserService {
    @Resource
    private AUserMapper aUserMapper;

    @Override
    public List<AUser> selectByLimit(Integer page, Integer limit) {
        if(page != null && limit != null){
            page = (page - 1) * limit;
        }else{
            page = 0;
            limit = 10;
        }
        return aUserMapper.selectByLimit(page,limit);
    }

    @Override
    public Integer count() {
        return aUserMapper.count();
    }

    @Override
    public AUser login(String username, String password) {
        //
        AUser aUser = aUserMapper.selectByUsername(username);
        if (aUser != null) {
            //将前端传递的密码 使用服务端相同的加密方式进行加密
            String enc = MD5Util.enc(password, username);
            if (enc.equals(aUser.getPassword())) {
                aUser.setPassword("");
                return aUser;
            }
        }

        return null;
    }

    @Override
    public Integer delByIds(String[] ids) {
        return aUserMapper.deleteByIds(ids);
    }

    @Override
    public List<AUser> queryByConditions(AUser aUser) {
        return aUserMapper.queryByConditions(aUser);
    }

    @Override
    public Integer addAuser(AUser aUser) {
        return aUserMapper.addAuser(aUser);
    }

    @Override
    public Integer editAuser(AUser aUser) {
        return aUserMapper.editAuser(aUser);
    }

    @Override
    public List<AUser> queryByConditions1(AUser aUser) {
        return aUserMapper.queryByConditions1(aUser);
    }

    @Override
    public Integer editAuser1(AUser aUser) {
        return aUserMapper.editAuser1(aUser);
    }


}
